package cn.iocoder.yudao.module.vote.dal.mysql.dept;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.vote.dal.dataobject.dept.VoteDeptDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.vote.controller.admin.dept.vo.*;

/**
 * 部门信息 Mapper
 *
 * @author moving
 */
@Mapper
public interface VoteDeptMapper extends BaseMapperX<VoteDeptDO> {

    default PageResult<VoteDeptDO> selectPage(VoteDeptPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<VoteDeptDO>()
                .likeIfPresent(VoteDeptDO::getName, reqVO.getName())
                .eqIfPresent(VoteDeptDO::getParentId, reqVO.getParentId())
                .eqIfPresent(VoteDeptDO::getSort, reqVO.getSort())
                .eqIfPresent(VoteDeptDO::getLeaderUserId, reqVO.getLeaderUserId())
                .eqIfPresent(VoteDeptDO::getPhone, reqVO.getPhone())
                .eqIfPresent(VoteDeptDO::getEmail, reqVO.getEmail())
                .eqIfPresent(VoteDeptDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(VoteDeptDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(VoteDeptDO::getSort));
    }

    default List<VoteDeptDO> selectList(VoteDeptExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<VoteDeptDO>()
                .likeIfPresent(VoteDeptDO::getName, reqVO.getName())
                .eqIfPresent(VoteDeptDO::getParentId, reqVO.getParentId())
                .eqIfPresent(VoteDeptDO::getSort, reqVO.getSort())
                .neIfPresent(VoteDeptDO::getParentId, reqVO.getParentIdNotRoot())
//                .eqIfPresent(VoteDeptDO::getLeaderUserId, reqVO.getLeaderUserId())
//                .eqIfPresent(VoteDeptDO::getPhone, reqVO.getPhone())
//                .eqIfPresent(VoteDeptDO::getEmail, reqVO.getEmail())
                .eqIfPresent(VoteDeptDO::getStatus, reqVO.getStatus())

//                .betweenIfPresent(VoteDeptDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(VoteDeptDO::getSort));
    }

    default VoteDeptDO getDeptByName(String name) {
        return selectOne(new LambdaQueryWrapperX<VoteDeptDO>()
                .eqIfPresent(VoteDeptDO::getName, name)
                .last("limit 1"));
    }

}
